package com.kingwood.algorithm.test200;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: 部门人力分配
 * https://fcqian.blog.csdn.net/article/details/134724995
 * @Date: 2024/3/29 18:29
 * @Modified By：
 * @Version 1.0
 */
public class BuMenRenLiFenPei {

    public static int getResult(int[] arr, int limit) {
        Arrays.sort(arr);
        int len = arr.length;
        int min = arr[len - 1];
        int max = arr[len - 1] + arr[len - 2];
        int ans = max;

        while (min <= max) {
            int mid = (min + max) / 2;
            if (checkHr(arr, mid, limit)) {
                ans = mid;
                max = mid - 1;
            } else {
                min = mid + 1;
            }
        }

        return ans;
    }

    public static boolean checkHr(int[] arr, int mid, int limit) {
        int len = arr.length;
        int l = 0;
        int r = len - 1;

        int needHr = 0;

        while (l <= r) {
            if (arr[l] + arr[r] <= mid) {
                l++;
            }
            r--;
            needHr++;
        }

        return limit >= needHr;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int limit = scanner.nextInt();
        scanner.nextLine();
        int[] arr = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int ans = getResult(arr, limit);
        System.out.println(ans);
    }
}
